package com.justnow.offer.q1;

/**
 * 三个线程交替执行，被CPU调度。如果调度的是t3那么执行的是t2.join()，转而去执行线程2中的任务，线程2会继续去执行t1.join()从而先去执行线程1的任务
 * 然后再一次打印B和C
 */
public class JoinDemo02 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("A");
        });

        Thread t2 = new Thread(() -> {
            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("B");
        });

        Thread t3 = new Thread(() -> {
            try {
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("C");
        });
        t3.start();
        t2.start();
        t1.start();
    }

}
